文档

使用Java SDK写入数据时报错The count of attribute columns exceeds the maximum:128

问题现象

使用表格存储Java SDK写入数据到数据表时出现如下报错:

The count of attribute columns exceeds the maximum:128

可能原因

写入数据到表格存储数据表时,一行最多支持写入1024列。在使用TableStoreWriter的过程中,客户端会有一个默认写入128列的限制。

解决方案

使用Java SDK构造TableStoreWriter客户端时,您可以通过修改MaxColumnsCount参数来适当调大一行默认写入的列数。

说明
final String endPoint = ""; 
String accessKeyId = System.getenv("OTS_AK_ENV");
String accessKeySecret = System.getenv("OTS_SK_ENV");
final String instanceName = "";

ClientConfiguration cc = new ClientConfiguration();
cc.setRetryStrategy(new DefaultRetryStrategy()); // 可定制重试策略,如果需要保证数据写入成功率,可采用更激进的重试策略。
AsyncClient asyncClient = new AsyncClient(endPoint, accessKeyId, accessKeySecret, instanceName, cc);

// 初始化
WriterConfig config = new WriterConfig();
config.setMaxBatchSize(4 * 1024 * 1024); // 配置一次批量导入请求的大小限制,默认值为4 MB。
config.setMaxColumnsCount(128); // 配置一行的列数的上限,默认值为128。
config.setBufferSize(1024); // 配置内存中最多缓冲的数据行数,默认值为1024,必须是2的指数倍。
config.setMaxBatchRowsCount(100); // 配置一次批量导入的行数上限,默认值为100。
config.setConcurrency(10); // 配置最大并发数,默认值为10。
config.setMaxAttrColumnSize(2 * 1024 * 1024); // 配置属性列的值大小上限,默认值为2 MB。
config.setMaxPKColumnSize(1024); // 配置主键列的值大小上限,默认值为1 KB。
config.setFlushInterval(10000); // 配置缓冲区flush的时间间隔,默认值为10。单位为秒。

// 配置一个callback,OTSWriter通过该callback反馈哪些导入成功,哪些行导入失败,该callback只简单的统计写入成功和失败的行数。

AtomicLong succeedCount = new AtomicLong();
AtomicLong failedCount = new AtomicLong();
TableStoreCallback<RowChange, ConsumedCapacity> callback = new SampleCallback(succeedCount, failedCount);
ExecutorService executor = Executors.newFixedThreadPool(2);
TableStoreWriter tablestoreWriter = new DefaultTableStoreWriter(asyncClient, tableName, config, callback, executor);

  • 本页导读 (1)
文档反馈